package com.example.SocialApplication.adapters;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.SocialApplication.R;

import java.util.List;

public class GalleryAdapter extends ArrayAdapter {
    private List list;
    private Context context;

    public GalleryAdapter(Context context, int textViewResourceId, List objects) {
        super(context, textViewResourceId, objects);
        this.list = objects;
        this.context = context;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = ((Activity) context).getLayoutInflater().inflate(R.layout.gallery_item, parent, false);
        }

        TextView text = (TextView) view.findViewById(R.id.name);
        text.setLayoutParams(new LinearLayout.LayoutParams(200, 100));
        if (position == 5) {
            text.setText("Добавить новый");
            view.setBackgroundColor(Color.GREEN);
        } else {
            text.setText(list.get(position).toString());
            view.setBackgroundColor(Color.BLUE);
        }
        return view;
    }
}
